<?php
namespace app\index\controller;
/**
 * Created by Submint Text.
 * User: hetaoren<452649510@qq.com>
 * Date: 2017/03/10
 * Explain: 订单控制器
 */
class Orders extends Base{
   /**
	* 查看订单列表
	*/
	public function index(){
        $diseaseList = model('disease')->field('diseaseId,diseaseName')->where(['dataFlag'=>1])->order('diseaseSort asc, diseaseId asc')->select();
        $this->assign("diseaseList",$diseaseList);
        $staffList = model('staffs')->where(['dataFlag'=>1,'staffRoleId'=>3])->column('staffId,staffName');
        $this->assign("staffList",$staffList);
        $this->assign("areaList",model('areas')->listQuery(0));
        $this->assign("staffRoleId",session("HTR_STAFF.staffRoleId"));
		return $this->fetch();
	}
    /**
     * 获取分页
     */
    public function pageQuery(){
        return model('Orders')->pageQuery();
    }
    /**
     * 跳去编辑页面
     */
    public function toEdit(){
        $id = input("id/d",0);
        $object = model('Orders')->get($id);
        $data['object'] = $object;        
        $diseaseList = model('disease')->field('diseaseId,diseaseName')->where(['dataFlag'=>1])->order('diseaseSort asc, diseaseId asc')->select();
        $this->assign("diseaseList",$diseaseList);
        return $this->fetch("edit",$data);
    }
    /**
     * 新增
     */
    public function add(){
        return model('Orders')->add();
    }
    /**
     * 编辑
     */
    public function edit(){
        return model('Orders')->edit();
    }
    /**
     * 删除订单
     */
    public function del(){
        return model('Orders')->del();
    }
    public function check_phone(){        
        $user_phone = input('post.user_phone');
        if($user_phone == '')return HTRReturn('客户联系方式不能为空');
        $user = model('users')->where(['dataFlag'=>1,'user_phone'=>$user_phone])->find();
        if(!$user)return HTRReturn('客户不存在');
        $user['shopId'] = model('staffs')->where(['dataFlag'=>1,'staffId'=>$user['staffId']])->value('shopId');
        $staffRoleId = session("HTR_STAFF.staffRoleId");
        if($staffRoleId == 2){
            if($user['shopId'] != session("HTR_STAFF.shopId"))return HTRReturn('该客户不是您店铺的客户');
        }elseif($staffRoleId == 3){
            if($user['staffId'] != session("HTR_STAFF.staffId"))return HTRReturn('该客户不是您的客户');
        }
        return HTRReturn("验证成功", 1, $user);
    }
    public function check_goods(){        
        $goodsSn = input('post.goodsSn');
        if($goodsSn == '')return HTRReturn('产品编号不能为空');
        $goods = model('goods')->where(['dataFlag'=>1,'goodsSn'=>$goodsSn])->find();
        if(!$goods)return HTRReturn('产品不存在');
        return HTRReturn("验证成功", 1, $goods);
    }
}
